package com.bodu.depress.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.global.annon.TraceLog;
import com.bodu.depress.entity.vo.DepressOptionsVo;
import com.bodu.depress.entity.request.DepressOptionsRequest;
import com.bodu.depress.service.DepressOptionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 题目选项 API
* @author Administrator
*/
@Api(tags = "题目选项 API")
@RestController
@RequestMapping("/depressOptions")
public class DepressOptionsController extends AbstractCommonController<DepressOptionsService, DepressOptionsRequest, DepressOptionsVo>{

    private final DepressOptionsService depressOptionsService;

    public DepressOptionsController(DepressOptionsService depressOptionsService) {
        this.depressOptionsService = depressOptionsService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(depressOptionsService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存题目选项")
    public Result<Integer> save(@RequestBody DepressOptionsRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(depressOptionsService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新题目选项")
    public Result<Integer> update(@RequestBody DepressOptionsRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(depressOptionsService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("题目选项-查询")
    public Result<List<DepressOptionsVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(depressOptionsService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("题目选项-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(depressOptionsService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("题目选项-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<DepressOptionsRequest> req) {
        return super.page(depressOptionsService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除题目选项")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(depressOptionsService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除题目选项")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(depressOptionsService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
